<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改租户管理')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <input name="projects" id="projects" type="hidden" th:value="${projects}">
        <form class="form-horizontal m" id="form-tenant-edit" th:object="${tenantInfo}">
            <input name="tenantId" th:field="*{tenantId}" type="hidden" required>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">序号：</label>
                <div class="col-sm-8">
                    <input name="serialNumber" th:field="*{serialNumber}" class="form-control" type="text" required>
                </div>
            </div>
			
			<div class="form-group">
			    <label class="col-sm-3 control-label is-required">项目名称：</label>
			    <div class="col-sm-8">
			        <input name="tenantProject" th:field="*{tenantProject}" class="form-control" type="text" required>
			    </div>
			</div>
			
			<div class="form-group">
			    <label class="col-sm-3 control-label is-required">租户楼层：</label>
			    <div class="col-sm-8">
			        <input name="tenantFloor" class="form-control" type="text" th:field="*{tenantFloor}" required>
<!--			        <select name="tenantFloor" class="form-control" id="tenantFloor" th:field="*{tenantFloor}" required>-->
<!--			            <option th:each="floorInfo:${floorInfos}" th:text="${floorInfo.floorName}" th:value="${floorInfo.floorName}"></option>-->
<!--			        </select>-->
			    </div>
			</div>
			
			<div class="form-group">
			    <label class="col-sm-3 control-label is-required">租户房间：</label>
			    <div class="col-sm-8">
			        <input name="tenantRoom" th:field="*{tenantRoom}" class="form-control" type="text" required>
			    </div>
			</div>
			
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">租户名称或单位：</label>
                <div class="col-sm-8">
                    <input name="tenantName" th:field="*{tenantName}" class="form-control" type="text" required>
                </div>
            </div>
            
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">租户面积(平方米)：</label>
                <div class="col-sm-8">
                    <input name="tenantArea" th:field="*{tenantArea}" class="form-control" type="text" required>
                </div>
            </div>
			
			<div class="form-group">
			    <label class="col-sm-3 control-label is-required">租赁单价(元)：</label>
			    <div class="col-sm-8">
			        <input name="tenantPrice" th:field="*{tenantPrice}" class="form-control" type="text" required>
			    </div>
			</div>
			
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">空关面积(平方米)：</label>
                <div class="col-sm-8">
                    <input name="emptyArea" th:field="*{emptyArea}" class="form-control" type="text" required>
                </div>
            </div>
			
			<div class="form-group">
			    <label class="col-sm-3 control-label is-required">空关单价(元)：</label>
			    <div class="col-sm-8">
			        <input name="emptyPrice" th:field="*{emptyPrice}" class="form-control" type="text" required>
			    </div>
			</div>

            <div class="form-group">
			    <label class="col-sm-3 control-label is-required">总金额：</label>
			    <div class="col-sm-8">
			        <input name="totalPrice" th:field="*{totalPrice}" class="form-control" type="text" required>
			    </div>
			</div>
<!--            <div class="form-group">
                <label class="col-sm-3 control-label ">收费系数：</label>
                <div class="col-sm-8">
                    <input name="chargeCoefficient" th:field="*{chargeCoefficient}" class="form-control" type="text" required>
                </div>
            </div> -->
            <div class="form-group">
                <label class="col-sm-3 control-label">租赁开始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="tenantTime" th:value="${#dates.format(tenantInfo.tenantTime, 'yyyy-MM-dd')}" class="form-control" placeholder="请填写日期" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">租赁到期时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="tenantEndTime" th:value="${#dates.format(tenantInfo.tenantEndTime, 'yyyy-MM-dd')}" class="form-control" placeholder="请填写日期" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label is-required">租赁期限：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="tenantTerm" th:field="*{tenantTerm}" class="form-control" type="text" required>-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="form-group">
                <label class="col-sm-3 control-label is-required">收费：</label>
                <div class="col-sm-8">
                    <div class="check-box" id="chooseCharge">
                        <label class="check-box"> <input type="checkbox"  name="charges" value="0" /> 物管费 </label>
                        <label class="check-box"> <input type="checkbox"  name="charges" value="1" /> 水费 </label>
                        <label class="check-box"> <input type="checkbox"  name="charges" value="2" /> 照明费 </label>
                        <label class="check-box"> <input type="checkbox"  name="charges" value="3" /> 动力费 </label>
                        <label class="check-box"> <input type="checkbox"  name="charges" value="4" /> 公用电费 </label>
                        <label class="check-box"> <input type="checkbox"  name="charges" value="5" /> 空调电费 </label>
                        <label class="check-box"> <input type="checkbox"  name="charges" value="6" /> 空调油费 </label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">电表：</label>
                <div class="col-sm-8">
                    <div class="check-box" id="chooseAmmeter">
                        <label class="check-box"> <input type="checkbox"  name="ammeter" value="0" /> A表 </label>
                        <label class="check-box"> <input type="checkbox"  name="ammeter" value="1" /> B表 </label>
                        <label class="check-box"> <input type="checkbox"  name="ammeter" value="2" /> C表 </label>
                        <label class="check-box"> <input type="checkbox"  name="ammeter" value="3" /> D表 </label>
                    </div>
                </div>
            </div> -->
			<div class="form-group">
			    <label class="col-sm-3 control-label is-required">付款方式：</label>
			    <div class="col-sm-8">
			        <input name="chargesType" th:field="*{chargesType}" class="form-control" type="text" required>
			    </div>
			</div>
			
			
            <div class="form-group">
                <label class="col-sm-3 control-label is-required" >状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box is-required" id="chooseStatus">
                        <label class="radio-box"> <input type="radio"  name="tenantStatus" value="0" /> 正常 </label>
                        <label class="radio-box"> <input type="radio"  name="tenantStatus" value="1" /> 退租 </label>
                        <label class="radio-box"> <input type="radio"  name="tenantStatus" value="2" /> 到期 </label>
                        <label class="radio-box"> <input type="radio"  name="tenantStatus" value="3" /> 空关 </label>
                    </div>
                </div>
            </div>
         <!--   <div class="form-group">
                <label class="col-sm-3 control-label is-required">分配项目：</label>
                <div class="col-sm-8">
                    <select name="projectId" id="projectId" class="form-control m-b"  >
                        <option th:each="SysProject:${projects}" th:text="${SysProject.projectName}" th:value="${SysProject.projectId}" th:field="*{projectId}"></option>
                    </select>
                </div>
            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "guomao/tenantManagement";
        /*将后台的值传入前台*/
        var tenantInfo = [[${tenantInfo}]];

        /*$(document).ready(function(){initChoice();})的简写
        * function () {}里面的内容是在页面都加载完才执行*/
        $(function () {
           // initChargeChoice();
            initStatusChoice();
           // initAmmeterChoice();
        })

        // /*将收费项目中，（数据库的值），回显到前端，并勾选上。
        // * 1、将收费的值赋给变量choice
        // * 2、判choice是否为null或""
        // * 3、定义数组将（0,1,2,3,...）中","去掉，存入数组choices
        // * 4、遍历数组，遍历前端，并将数组的值与input标签内值比较
        // * 5、判断数组中值（存入数据库的值）是否等于标签上的值，若等于则勾选*/
        // function initChargeChoice(){
        //     var choice = tenantInfo.charges
        //     if (choice!=null&&choice!=""){
        //         var choices = choice.split(",");
        //         for (var i=0;i<choices.length;i++){
        //             $("#chooseCharge input").each(function () {
        //                 /*$(this)取出当前对象并转换为jQuery对象*/
        //                 if ($(this).val()==choices[i]){
        //                     $(this).parent().addClass("checked")
        //                     $(this).attr("checked",true)
        //                 }
        //             });
        //         }
        //     }

        // }

        /*租户状态回显*/
        function initStatusChoice(){
            var choice = tenantInfo.tenantStatus
            console.log("choice="+choice)
            $("#chooseStatus input").each(function () {
            if($(this).val()==choice){
                $(this).parent().addClass("checked")
                $(this).attr("checked",true)
            }
            });
        }

        // /*电表回显*/
        // function initAmmeterChoice(){
        //     var choice = tenantInfo.ammeter
        //     if (choice!=null&&choice!=""){
        //         var choices = choice.split(",");
        //         for (var i=0;i<choices.length;i++){
        //             $("#chooseAmmeter input").each(function () {
        //                 /*$(this)取出当前对象并转换为jQuery对象*/
        //                 if ($(this).val()==choices[i]){
        //                     $(this).parent().addClass("checked")
        //                     $(this).attr("checked",true)
        //                 }
        //             });
        //         }
        //     }
        // }


        $("#form-tenant-edit").validate({
            focusCleanup: true
        });

// 			表单提交操作
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-tenant-edit').serialize());
            }
        }

        $("input[name='tenantTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='tenantEndTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>